from sqlalchemy import Column, BigInteger, String, SmallInteger, DateTime, Date
from app.config.database import Base
from datetime import datetime, date
from pydantic import BaseModel, ConfigDict
from typing import Optional

class User(Base):
    __tablename__ = "sys_user"
    
    id = Column(BigInteger, primary_key=True, autoincrement=True, comment="用户ID")
    username = Column(String(50), unique=True, index=True, nullable=False, comment="用户名")
    password = Column(String(100), nullable=False, comment="密码（加密存储）")
    real_name = Column(String(50), nullable=False, comment="真实姓名")
    status = Column(SmallInteger, nullable=False, default=1, comment="状态：0-禁用 1-启用")
    phone = Column(String(20), comment="手机号")
    email = Column(String(100), comment="邮箱")
    create_time = Column(DateTime, default=datetime.utcnow, nullable=False, comment="创建时间")
    update_time = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False, comment="更新时间")

    __table_args__ = (
        # 索引已经在字段定义中声明
    )

class UserInDB(BaseModel):
    id: int
    username: str
    password: str
    real_name: str
    status: int = 1
    phone: Optional[str] = None
    email: Optional[str] = None
    create_time: Optional[datetime] = None
    update_time: Optional[datetime] = None

    model_config = ConfigDict(from_attributes=True)